Skip to content

gh-154014: Initialize cold executor vm_data fields#154142

Merged
Fidget-Spinner merged 7 commits into
python:mainfrom
BHUVANSH855:fix-154014-jit-vm-data-assert
Jul 22, 2026
Merged

gh-154014: Initialize cold executor vm_data fields#154142
Fidget-Spinner merged 7 commits into
python:mainfrom
BHUVANSH855:fix-154014-jit-vm-data-assert

Conversation

@BHUVANSH855

Copy link
Copy Markdown
Contributor

Issue

Fixes gh-154014.

Summary

make_cold_executor() allocates cold executors directly via
allocate_executor() and bypasses _Py_ExecutorInit(). As a result,
vm_data.valid and vm_data.pending_deletion remain uninitialized.

During interpreter shutdown, interpreter_clear() asserts that
cold->vm_data.valid is true, causing assertion failures when CPython is
built with --enable-experimental-jit --with-assertions.

This change initializes the required vm_data fields for cold executors,
restoring the expected invariant during shutdown.

Testing

Reproduced the original crash reported in the issue using:

./configure --enable-experimental-jit --with-assertions
make -j$(nproc)

Before this change, _bootstrap_python aborted with:

Assertion `cold->vm_data.valid' failed.

After this change:

  • make -j$(nproc) completes successfully.
  • The full CPython regression test suite passes.

@bedevere-app

bedevere-app Bot commented Jul 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@Fidget-Spinner Fidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just needs style cleanups.

Comment thread Python/optimizer.c
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated
Comment thread Python/optimizer.c Outdated
@Fidget-Spinner

Copy link
Copy Markdown
Member

Please add a news entry as well, and a test reproducer in Lib/test/test_capi/test_opt.py.

@bedevere-app

bedevere-app Bot commented Jul 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@BHUVANSH855

Copy link
Copy Markdown
Contributor Author

Thanks for the review @Fidget-Spinner

I've addressed the requested changes:

  • removed the stray formatting changes,
  • added a NEWS entry,
  • added a regression test in Lib/test/test_capi/test_opt.py.

The CI is now running on the updated branch. I'd appreciate another look when you have a chance. Thanks!

Comment thread Python/optimizer.c
@BHUVANSH855
BHUVANSH855 requested a review from cocolato July 20, 2026 12:30

@cocolato cocolato left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can release unregistered cold executors directly

Comment thread Python/optimizer.c Outdated
@BHUVANSH855
BHUVANSH855 requested a review from cocolato July 20, 2026 12:47
@cocolato

Copy link
Copy Markdown
Member

Thanks! let's wait for Ken Jin's review :)

@Fidget-Spinner

Copy link
Copy Markdown
Member

@cocolato do you know if this fixes the reproducer on your system? If you're able to, can you please check? Really appreciate being able to outsource some of the work to you, thanks a lot!

@cocolato

cocolato commented Jul 22, 2026

Copy link
Copy Markdown
Member

@cocolato do you know if this fixes the reproducer on your system? If you're able to, can you please check? Really appreciate being able to outsource some of the work to you, thanks a lot!

I have verified that the cold executor assertion in the issue has been fixed. I also reproduced a scenario where _PyJIT_Compile() fails; the original Py_DECREF(cold) would incorrectly call unlink_executor(), but this issue has been resolved by using _PyExecutor_Free(cold) instead.

@Fidget-Spinner
Fidget-Spinner merged commit d1174a4 into python:main Jul 22, 2026
77 checks passed
@Fidget-Spinner Fidget-Spinner added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 22, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @BHUVANSH855 for the PR, and @Fidget-Spinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 22, 2026

Copy link
Copy Markdown

GH-154457 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 22, 2026
@Fidget-Spinner

Copy link
Copy Markdown
Member

Note: The SC has paused all JIT development with the exception of bugfixes. As this is a bugfix, I'm merging it.

Fidget-Spinner pushed a commit that referenced this pull request Jul 22, 2026
…GH-154457)

gh-154014: Initialize cold executor vm_data fields (GH-154142)
(cherry picked from commit d1174a4)

Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT build crashes on assertions (since 3.15): Python/pystate.c:925: interpreter_clear: Assertion 'cold->vm_data.valid' failed.

3 participants